package zjs.dc.controller;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

/**
 * @Class:
 * @Author: kongcb
 * @Description: 行政许可详情_信用中国:t_credit_china_license_detail,数据来源是国家信用信息中心，全量更新
 * @Date: 2021/12/15 9:24
 */
public class TCreditChinaLicenseDetail {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder().appName("t_credit_china_license_detail").enableHiveSupport().getOrCreate();
        spark.sparkContext().setLogLevel("ERROR");
        Dataset<Row> zs_data = spark.sql("select * from xy_pdm.sgs_pub_permission_new");
        long zs_count = zs_data.count();
        if(zs_count>0) {
            zs_data.createOrReplaceTempView("tmp_permission");
            spark.sql("select " +
                    "md5(concat(if(xyzg.xk_wsh is not null and xyzg.xk_wsh!='',xyzg.xk_wsh,xyzg.createtime_dept),xyzg.company_id))," +
                    "xyzg.company_id," +
                    "xyzg.company_id," +
                    "xyzg.company_name," +
                    "xyzg.xk_wsh," +
                    "xyzg.xk_xkws,\n" +
                    "xyzg.xk_xklb,\n" +
                    "xyzg.xk_nr,\n" +
                    "xyzg.xk_xkjg,\n" +
                    "xyzg.xk_jdrq,\n" +
                    "xyzg.xk_yxqzi,\n" +
                    "xyzg.xk_zt," +
                    "xyzg.com_province," +
                    "date_format(current_date(),'yyyyMMdd')," +
                    "'1' as isadd " +
                    "from tmp_permission xyzg").dropDuplicates().createOrReplaceTempView("xyzg");
            spark.sql("insert overwrite table a_dc_ep_incr.t_credit_china_license_detail select * from xyzg");
        }
        spark.stop();
    }
}
